//
//  HelpModel.m
//  RainbowFM
//
//  Created by Kratos on 14/12/24.
//  Copyright (c) 2014年 RB. All rights reserved.
//

#import "HelpAPI.h"

#import "AFAppDotNetAPIClient.h"

@implementation HelpAPI

-(void)fetchHelpListWithType:(NSString *)type
                 currentPage:(NSString *)currentPage
                    pageSize:(NSString *)pageSize
                      result:(void (^)(NSArray *list, NSString *msg))res
{
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    
    if (!type || !currentPage || !pageSize) {
        res(nil,@"缺少 类型 或 当前页 或 每页条数");
        return;
    }else
    {
        [params setObject:type forKey:@"type"];
        [params setObject:currentPage forKey:@"currentPage"];
        [params setObject:pageSize forKey:@"pageSize"];
    }
    
    [[AFAppDotNetAPIClient sharedClient] POST:VIDEO_BASE_URL
                                   parameters:@{@"serviceName":@"video_queryHandy_req",
                                                @"callType":@"002",
                                                @"params":params
                                                }
                                      success:^(NSURLSessionDataTask *task, id responseObject) {
                                          if ([responseObject[@"returnCode"] isEqualToString:@"000000"]) {
                                              res(responseObject[@"result"][@"list"],nil);
                                          }
                                          else{
                                              res(nil,responseObject[@"errorMsg"]);
                                          }
                                          
                                      }
                                      failure:^(NSURLSessionDataTask *task, NSError *error) {
                                          res(nil,@"erroe for fetchHelpList");
                                      }];
}

-(void)addHelpInfoWithDesct:(NSString *)desct
                  detilDesc:(NSString *)detilDesc
                     picUrl:(NSString *)picUrl
                      meUrl:(NSString *)meUrl
                       type:(NSString *)type
                     result:(void (^)(BOOL success, NSString *msg))res
{
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    
    if (picUrl) {
        [params setObject:picUrl forKey:@"picUrl"];
    }else{
        [params setObject:@"" forKey:@"picUrl"];
    }
    
    if (meUrl) {
        [params setObject:meUrl forKey:@"meUrl"];
    }else{
        [params setObject:@"" forKey:@"meUrl"];
    }
    
    if (!type || !desct || !detilDesc) {
        res(nil,@"缺少 类型 或 简介 或 详情");
        return;
    }else
    {
        [params setObject:type forKey:@"type"];
        [params setObject:desct forKey:@"desct"];
        [params setObject:detilDesc forKey:@"detilDesc"];
    }
    
    [[AFAppDotNetAPIClient sharedClient] POST:VIDEO_BASE_URL
                                   parameters:@{@"serviceName":@"video_addHandy_resp",
                                                @"callType":@"002",
                                                @"params":params
                                                }
                                      success:^(NSURLSessionDataTask *task, id responseObject) {
                                          if ([responseObject[@"returnCode"] isEqualToString:@"000000"]) {
                                              res(YES,nil);
                                          }
                                          else{
                                              res(NO,responseObject[@"errorMsg"]);
                                          }
                                          
                                      }
                                      failure:^(NSURLSessionDataTask *task, NSError *error) {
                                          res(NO,@"erroe for addHelpInfo");
                                      }];

}

@end
